package com.eshop.we.common;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.multipart.MultipartResolver;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * Servlet Filter implementation class CommonFilter
 */
public class CommonFilter implements Filter {
	
	private MultipartResolver multipartResolver = null;

	public static Set<String> urls= new HashSet<>();

	@SuppressWarnings("unchecked")
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		ParameterRequest requestWrapper = null;
		HttpServletRequest hr = (HttpServletRequest) request;
		requestWrapper = new ParameterRequestWrapper(hr,urls);
		//}
	//	RespDataResponse respDataResponse = new RespDateResponseWrapper((HttpServletResponse)response);
		chain.doFilter(requestWrapper, response);
	//	response.getWriter().write(respDataResponse.getTextContent());
	}
	@Override
	public void init(FilterConfig fConfig) throws ServletException {
		// 注入bean
		ApplicationContext ac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(fConfig.getServletContext());
		multipartResolver = ((MultipartResolver) ac.getBean("multipartResolver", MultipartResolver.class));
		urls.add("/wxauto/login/");
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}
}